﻿using System.Collections;
using Gp.Scripts.Data;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.GUI;
using Gp.Scripts.Core;
using Gp.Scripts.Core.Skill;

namespace Gp.Scripts.Core {
    /// <summary>
    /// 作用于自身的技能
    /// </summary>
    public abstract class SelfAbilityEntity : AbilitySkillEntity {
        // protected SelfAbilityEntity(SkillEntityConfig config) : base(config) { }

        public override void Display() {
            Global.Get<GridBattleGUISystem>().ConformClick(TriggerSkill, CancelSkill);
        }

        private void TriggerSkill() {
            HumanExecute(SkillContext.Empty);
        }

        protected void CancelSkill() {
            Global.Get<BattleSystem>().ToLastState();
        }


        public override SkillContext GetAIContext() {
            return SkillContext.Empty;
        }


        public override void CleanUp() {
            Global.Get<GridBattleGUISystem>().ClearConformClick();
        }
    }
    
    
    
    public abstract class SelfMagicEntity<T> : MagicSkillEntity<T> where T : MagicEntityConfig {
        // protected SelfMagicEntity(T data) : base(data) { }

        public override void Display() {
            Global.Get<GridBattleGUISystem>().ConformClick(TriggerSkill, CancelSkill);
        }

        private void TriggerSkill() {
            HumanExecute(SkillContext.Empty);
        }

        protected void CancelSkill() {
            Global.Get<BattleSystem>().ToLastState();
        }


        public override SkillContext GetAIContext() {
            return SkillContext.Empty;
        }


        public override void CleanUp() {
            Global.Get<GridBattleGUISystem>().ClearConformClick();
        }
    }




    public interface IPassiveAbility { }

    public abstract class PassiveAbility<T> : SkillEntity, IPassiveAbility where T : BaseBuff {
        // protected PassiveAbility(SkillEntityConfig config) : base(config) { }

        protected abstract T GetBuff();

        protected override void OnInit() {
            CheckBuff();
            base.OnInit();
        }


        public override IEnumerator OnTurnStart() {
            CheckBuff();
            
            yield break;
        }


        private void CheckBuff() {
            var buff = UnitReference.ComBuff.GetBuff<T>();
            if (buff == null) {
                UnitReference.ComBuff.AddBuff(GetBuff());
            }
        }

        public sealed override DisableReason CanSelect() {
            return base.CanSelect();
        }
    }
}